package com.yijiu.response;

import java.text.DecimalFormat;

import org.json.JSONException;
import org.json.JSONObject;

import com.yijiu.network.Response;
import com.yijiu.resource.RequestFieldFromServer;

/**
 * 账户信息请求的响应
 * 
 * @author TangChao
 */
public class RequestAccountInfoResponse extends Response {

	public RequestFieldFromServer field;

	@Override
	protected void jsonToObject() {
		field = new RequestFieldFromServer();
		try {
			JSONObject jsonObject = reposonJson.getJSONObject("result");
			field.availableBalance = formatNum(jsonObject.optDouble("availableBalance"));
			field.certifyStatus = jsonObject.optString("certifyStatus");
			field.message = jsonObject.optString("message");
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public String formatNum(double value) {
		String retValue = null;
		DecimalFormat df = new DecimalFormat();
		df.setMinimumFractionDigits(0);
		df.setMaximumFractionDigits(2);
		retValue = df.format(value);
		retValue = retValue.replaceAll(",", "");
		return retValue;
	}
}
